home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 848 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.3 KB

  1. Path: chronicle.mti.sgi.com!austern
  2. From: Rob Stewart <stew@datalytics.com>
  3. Newsgroups: comp.std.c++
  4. Subject: Re: istrstreams and width
  5. Date: 25 Mar 1996 10:22:46 PST
  6. Organization: Datalytics, Inc
  7. Approved: austern@isolde.mti.sgi.com
  8. Message-ID: <3156E26D.74@datalytics.com>
  9. References: <4ibvn8$4gr@venus.roc.csci.csc.com>
  10. NNTP-Posting-Host: isolde.mti.sgi.com
  11. X-Original-Date: Mon, 25 Mar 1996 13:14:05 -0500
  12. X-Mailer: Mozilla 2.0 (WinNT; I)
  13. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  14.     iQBVAwUBMVbknUy4NqrwXLNJAQEojQIAyn2r+TTkh8t7+hLV3RnNdcZ2j+anlSU/
  15.     Gu+/yGvUrw9ki75FMgGZtBQG9ks02lCIvta6MM9UQz1rVqgkfaceDQ==
  16.     =z+Rj
  17. Originator: austern@isolde.mti.sgi.com
  18.  
  19. Tim Ottinger wrote:
  20. > We've already worked around this (identified two way to do so) but we
  21. > wonder why it doesn't work this way:
  22. > Given:
  23. >     istrstream source;
  24. >     int i;
  25. >     string s;
  26. >     source >> setw(2) >> i >> s;
  27. > With fixed length fields (yes, we have to read mainframe data from time to
  28. > time, and a few other odd sources), sometimes the fields are butted up against
  29. > each other, and sometimes the strings have initial digit characters i them.
  30. > When the stream contains "01115 N Neil", it would be nice if "01" and "115 N
  31. > Neil" were broken out, but every compiler we try pulls "01115" as the number,
  32. > and "N Neil" is the string.
  33. > Of course, if we insert whitespace or use read, this works.  And we should use
  34. > read() because we're doing fixed length, but I was wondering why setw()
  35. > doesn't apply to integer extractors.
  36. > Surely a lot of people have to read fixed-length records, and this is a common
  37. > thing.
  38. > Any thoughts?
  39.  
  40. The setw manipulator, like the width mf, only specify a minimum 
  41. field width.  Thus, neither was intended to indicate the maximum 
  42. number of characters to read.  You only solutions are to use 
  43. read or to parse the longer string yourself.
  44.  
  45. -- 
  46. Robert Stewart        | My opinions are usually my own.
  47. Datalytics, Inc.    | stew@datalytics.com
  48. ---
  49. [ comp.std.c++ is moderated.  To submit articles: Try just posting with your 
  50.                 newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  51.   comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  52.   Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  53.   Comments? mailto:std-c++-request@ncar.ucar.edu 
  54. ]
  55.